<!doctype html>
<html class="no-js" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Amaze UI Admin table Examples</title>
  <meta name="description" content="这是一个 table 页面">
  <meta name="keywords" content="table">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <link rel="icon" type="image/png" href="/assets/i/favicon.png">
  <link rel="apple-touch-icon-precomposed" href="/assets/i/app-icon72x72@2x.png">
  <meta name="apple-mobile-web-app-title" content="Amaze UI" />
  <link rel="stylesheet" href="/assets/css/amazeui.min.css"/>
  <link rel="stylesheet" href="/assets/css/admin.css">
</head>
<body onload="getUserOfTable('all',1)">
<!--[if lte IE 9]>
<p class="browsehappy">你正在使用<strong>过时</strong>的浏览器，Amaze UI 暂不支持。 请 <a href="http://browsehappy.com/" target="_blank">升级浏览器</a>
  以获得更好的体验！</p>
<![endif]-->

<header class="am-topbar am-topbar-inverse admin-header" id="username" th:alt="${username}">
  <div class="am-topbar-brand">
    <strong>NCU 网上通讯录</strong> <small>后台管理</small>
  </div>

  <button class="am-topbar-btn am-topbar-toggle am-btn am-btn-sm am-btn-success am-show-sm-only" data-am-collapse="{target: '#topbar-collapse'}"><span class="am-sr-only">导航切换</span> <span class="am-icon-bars"></span></button>

  <div class="am-collapse am-topbar-collapse" id="topbar-collapse">

    <ul class="am-nav am-nav-pills am-topbar-nav am-topbar-right admin-header-list">
      <li><a href="javascript:;"><span class="am-icon-envelope-o"></span> 收件箱 <span class="am-badge am-badge-warning">5</span></a></li>
      <li class="am-dropdown" data-am-dropdown>
        <a class="am-dropdown-toggle" data-am-dropdown-toggle href="javascript:;">
          <span class="am-icon-users"></span> 管理员 <span class="am-icon-caret-down"></span>
        </a>
        <ul class="am-dropdown-content">
          <li><a href="#"><span class="am-icon-user"></span> 资料</a></li>
          <li><a href="#"><span class="am-icon-power-off"></span> 退出</a></li>
        </ul>
      </li>
      <!--<li class="am-hide-sm-only"><a href="javascript:;" id="admin-fullscreen"><span class="am-icon-arrows-alt"></span> <span class="admin-fullText">开启全屏</span></a></li>-->
    </ul>
  </div>
</header>

<div class="am-cf admin-main">
  <!-- sidebar start -->
  <div class="admin-sidebar am-offcanvas" id="admin-offcanvas">
    <div class="am-offcanvas-bar admin-offcanvas-bar">
      <ul class="am-list admin-sidebar-list">
        <li><a href="/loginPage"><span class="am-icon-home"></span> 首页</a></li>
        <li class="admin-parent">
          <a class="am-cf" data-am-collapse="{target: '#collapse-nav'}"><span class="am-icon-file"></span> 页面模块 <span class="am-icon-angle-right am-fr am-margin-right"></span></a>
          <ul class="am-list am-collapse admin-sidebar-sub am-in" id="collapse-nav">
            <li><a href="admin-user.html" class="am-cf"><span class="am-icon-check"></span> 修改个人资料<span class="am-icon-star am-fr am-margin-right admin-icon-yellow"></span></a></li>
            <li><a href="admin-log.html"><span class="am-icon-calendar"></span> 系统日志</a></li>
          </ul>
        </li>
        <li><a href="/admin/table"><span class="am-icon-table"></span> 表格</a></li>
        <li><a href="admin-form.html"><span class="am-icon-pencil-square-o"></span> 表单</a></li>
        <li><a href="#"><span class="am-icon-sign-out"></span> 注销</a></li>
      </ul>

      <div class="am-panel am-panel-default admin-sidebar-panel">
        <div class="am-panel-bd">
          <p><span class="am-icon-bookmark"></span> 公告</p>
          <p>时光静好，与君语；细水流年，与君同。—— NCU</p>
        </div>
      </div>

      <div class="am-panel am-panel-default admin-sidebar-panel">
        <div class="am-panel-bd">
          <p><span class="am-icon-tag"></span> wiki</p>
          <p>Welcome to NCU online address book</p>
        </div>
      </div>
    </div>
  </div>
  <!-- sidebar end -->

  <!-- content start -->
  <div class="admin-content">
    <div class="admin-content-body">
      <div class="am-cf am-padding am-padding-bottom-0">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">用户管理</strong> / <small>Table</small></div>
      </div>

      <hr>

      <div class="am-g">
        <div class="am-u-sm-12 am-u-md-6">
          <div class="am-btn-toolbar">
            <div class="am-btn-group am-btn-group-xs">
              <button type="button" class="am-btn am-btn-default"><span class="am-icon-plus"></span> 新增</button>
              <button type="button" class="am-btn am-btn-default"><span class="am-icon-save"></span> 保存</button>
              <button type="button" class="am-btn am-btn-default"><span class="am-icon-archive"></span> 审核</button>
              <button type="button" class="am-btn am-btn-default"><span class="am-icon-trash-o"></span> 删除</button>
            </div>
          </div>
        </div>
        <div class="am-u-sm-12 am-u-md-3">
          <div class="am-form-group">
            <select id="table" data-am-selected="{btnSize: 'sm'}" >
              <option value="all" onclick="getUserOfTable('all',1)">所有用户</option>
              <option value="normal" onclick="getUserOfTable('normal',1)">正常用户</option>
              <option value="disabled" onclick="getUserOfTable('disabled',1)">待审核用户</option>
              <option value="locked" onclick="getUserOfTable('locked',1)">被禁用用户</option>
            </select>
          </div>
        </div>
        <div class="am-u-sm-12 am-u-md-3">
          <div class="am-input-group am-input-group-sm">
            <input type="text" class="am-form-field">
          <span class="am-input-group-btn">
            <button class="am-btn am-btn-default" type="button">搜索</button>
          </span>
          </div>
        </div>
      </div>

      <div class="am-g">
        <div class="am-u-sm-12" id="table-div">
			
        <!--  用户信息-->
			
        </div>
      </div>
    </div>

    <footer class="admin-content-footer">
      <hr>
      <p class="am-padding-left">© 2019 AllMobilize, Inc. Licensed under MIT license.</p>
    </footer>

  </div>
  <!-- content end -->
</div>

<a href="#" class="am-icon-btn am-icon-th-list am-show-sm-only admin-menu" data-am-offcanvas="{target: '#admin-offcanvas'}"></a>

<footer>
  <hr>
  <p class="am-padding-left">© 2014 AllMobilize, Inc. Licensed under MIT license.</p>
</footer>

<!--[if lt IE 9]>
<script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
<script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
<script src="/assets/js/amazeui.ie8polyfill.min.js"></script>
<![endif]-->

<!--[if (gte IE 9)|!(IE)]><!-->
<script src="/assets/js/jquery.min.js"></script>
<!--<![endif]-->
<script src="/assets/js/amazeui.min.js"></script>
<script src="/assets/js/app.js"></script>
<script src="/assets/js/Util.js"></script>
<script>
 
	// select change绑定
    $('#table').change(function () {
      
      var option=$('#table').val();
      console.info("table::",option);
      getUserOfTable(option,1);
    });
  /*
    //获取用户个数
	function getNum(tip) {
		
        var num;
        $.ajax({

            type:'POST',
            url:'/user/'+tip+'/num',
			async:'false',
            success:function (data) {
                num = data;
                console.info("num::"+num);
            }
        });
        
        return num;
    }*/
	
    //获取用户信息并显示
  function getUserOfTable(tip,init) {
    
      var num=0;
    
            $.ajax({
    
              type:'POST',
              url:'/user/'+tip,
              dataType:'JSON',
              async:'false',
              data:{
                'pageNumber':init,
                'pageSize':15
              },
              success:function (data) {
      
                var obj = data;
                
                var s='<form class="am-form">\n' +
                        '            <table class="am-table am-table-striped am-table-hover table-main">\n' +
                        '              <thead>\n' +
                        '              <tr>\n' +
                        '                <th class="table-check"><input type="checkbox" /></th><th class="table-id">ID</th><th class="table-title">用户名</th><th class="table-type">状态</th><th class="table-author am-hide-sm-only">注册时间</th><th class="table-date am-hide-sm-only">登录次数</th><th class="table-set">操作</th>\n' +
                        '              </tr>\n' +
                        '              </thead>\n' +
                        '              <tbody>\n';
                console.info("data:::",data);
      
                for (var i in obj) {
        
                  ++num;
                  var id=data[i].username;
                  var name=data[i].name;
                  var reTime=timestampToTime(data[i].registerTime);
                  var loTime=data[i].loginTime==null?"未登录":timestampToTime(data[i].loginTime);
                  var times=data[i].loginTimes;
                  var disabled=data[i].enabled;
                  var locked=data[i].locked;
        
                  var status;
        
                  console.info("tip:::",tip);
        
                  if (tip=='normal') {
          
                    console.info("normal::正常用户",name);
                    status = "正常";
                    s+='          <tr>\n' +
                            '                <td><input type="checkbox" /></td>\n' +
                            '                <td>'+id+'</td>\n' +
                            '                <td>'+name+'</td>\n' +
                            '                <td>'+status+'</td>\n' +
                            '                <td class="am-hide-sm-only">'+reTime+'</td>\n' +
                            '                <td class="am-hide-sm-only">'+times+'</td>\n' +
                            '                <td>\n' +
                            '                  <div class="am-btn-toolbar">\n' +
                            '                    <div class="am-btn-group am-btn-group-xs">\n' +
                            '                      <button class="am-btn am-btn-default am-btn-xs am-text-secondary"><span class="am-icon-pencil-square-o"></span> 禁用用户</button>\n' +
                            '                      <button class="am-btn am-btn-default am-btn-xs am-hide-sm-only"><span class="am-icon-copy"></span> 查看用户</button>\n' +
                            '                    </div>\n' +
                            '                  </div>\n' +
                            '                </td>\n' +
                            '              </tr>\n';
                  }
                  else if (tip==='disabled') {
                    status = "审核中";
                    s+='          <tr>\n' +
                            '                <td><input type="checkbox" /></td>\n' +
                            '                <td>'+id+'</td>\n' +
                            '                <td>'+name+'</td>\n' +
                            '                <td>'+status+'</td>\n' +
                            '                <td class="am-hide-sm-only">'+reTime+'</td>\n' +
                            '                <td class="am-hide-sm-only">'+times+'</td>\n' +
                            '                <td>\n' +
                            '                  <div class="am-btn-toolbar">\n' +
                            '                    <div class="am-btn-group am-btn-group-xs">\n' +
                            '                      <button  class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick=" changeDisabledStatus('+id+','+tip+','+init+')"><span class="am-icon-pencil-square-o"></span> 审核通过</button>\n' +
                            '                      <button class="am-btn am-btn-default am-btn-xs am-hide-sm-only"><span class="am-icon-search-minus"></span> 查看用户</button>\n' +
                            '                      <button class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only"><span class="am-icon-trash-o"></span> 删除用户</button>\n' +
                            '                    </div>\n' +
                            '                  </div>\n' +
                            '                </td>\n' +
                            '              </tr>\n';
                  }
                  else if (tip=='locked'){
          
                    status="被禁用";
          
                    s+='          <tr>\n' +
                            '                <td><input type="checkbox" /></td>\n' +
                            '                <td>'+id+'</td>\n' +
                            '                <td>'+name+'</td>\n' +
                            '                <td>'+status+'</td>\n' +
                            '                <td class="am-hide-sm-only">'+reTime+'</td>\n' +
                            '                <td class="am-hide-sm-only">'+times+'</td>\n' +
                            '                <td>\n' +
                            '                  <div class="am-btn-toolbar">\n' +
                            '                    <div class="am-btn-group am-btn-group-xs">\n' +
                            '                      <button class="am-btn am-btn-default am-btn-xs am-text-secondary"><span class="am-icon-pencil-square-o"></span> 解除禁用</button>\n' +
                            '                      <button class="am-btn am-btn-default am-btn-xs am-hide-sm-only"><span class="am-icon-copy"></span> 查看用户</button>\n' +
                            '                    </div>\n' +
                            '                  </div>\n' +
                            '                </td>\n' +
                            '              </tr>\n';
                  }
                  else {
                    if (disabled==0)
                      status="审核中";
                    else if(locked==0)
                      status="被禁用";
                    else
                      status="正常";
          
                    s+='          <tr>\n' +
                            '                <td><input type="checkbox" /></td>\n' +
                            '                <td>'+id+'</td>\n' +
                            '                <td>'+name+'</td>\n' +
                            '                <td>'+status+'</td>\n' +
                            '                <td class="am-hide-sm-only">'+reTime+'</td>\n' +
                            '                <td class="am-hide-sm-only">'+times+'</td>\n' +
                            '                <td>\n' +
                            '                  <div class="am-btn-toolbar">\n' +
                            '                    <div class="am-btn-group am-btn-group-xs">\n' +
                            '                      <button class="am-btn am-btn-default am-btn-xs am-hide-sm-only"><span class="am-icon-copy"></span> 查看用户</button>\n' +
                            '                    </div>\n' +
                            '                  </div>\n' +
                            '                </td>\n' +
                            '              </tr>\n';
                  }
                }
      
                s+= '              </tbody>\n' +
                        '            </table>\n' +
                        '            <div class="am-cf">\n' +
                        '             <p ">共 '+num+' 条记录</p>\n' +
                        '              <div class="am-fr">\n' +
                        '                <ul class="am-pagination">\n' +
                        '                  <li class="am-disabled"><a href="#">«</a></li>\n' +
                        '                  <li class="am-active"><a href="#">1</a></li>\n' +
                        '                  <li value=""><a href="#">2</a></li>\n' +
                        '                  <li><a href="#">3</a></li>\n' +
                        '                  <li><a href="#">4</a></li>\n' +
                        '                  <li><a href="#">5</a></li>\n' +
                        '                  <li><a href="#">»</a></li>\n' +
                        '                </ul>\n' +
                        '              </div>\n' +
                        '            </div>\n' +
                        '            <hr />\n' +
                        '            <p>注：.....</p>\n' +
                        '          </form>';
      
                $('#table-div').html(s);
              }
            });
  }
  
  function changeDisabledStatus(id,tip,init) {
    //var id=$(this).id;
    console.info("id ::::"+id);
    //  getUserOfTable(tip,init);
    $.ajax({
    
      type:'POST',
      url:'/user/update/enabled',
      data:{
        "name":id,
        "enabled":1
      }
      /*success:function (data) {
        num = data;
        console.info("num::"+num);
      }*/
    });
  }
</script>
</body>
</html>
